/**
 * 
 */
package com.eagle.coders.security.beans;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.eagle.coders.common.bean.annotations.PropertyConstraints;
import com.eagle.coders.common.bean.annotations.RadioButton;
import com.eagle.coders.common.bean.annotations.RadioButtons;
import com.eagle.coders.common.bean.annotations.ResourceKey;
import com.eagle.coders.common.bean.annotations.UiComponentPosition;
import com.eagle.coders.common.bean.annotations.UnBound;
import com.eagle.coders.common.bean.annotations.type.MandatoryType;
import com.eagle.coders.common.bean.annotations.type.StringInputCaseType;
import com.eagle.coders.common.bean.annotations.type.TextFiledInputDataType;
import com.eagle.coders.security.type.UserTitlesEnum;


/**
 * @author Anees
 *
 */
@Entity
@Table(name = "eagle_roles")
@SequenceGenerator(name="role_gen_seq", sequenceName="eagle_gen_seq")
public class RolesBean implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private Integer id;
	
	private String role;
	
	private String description;
	
	private List<PermissionsBean> permissions;
	
	private List<LevelsBean> levelBeans;
	
	private Boolean isAllowed;
	
	private Date roleDate;
	
	private String destinationType;
	
	private UserTitlesEnum roleTitle;


	/**
	 * @return the id
	 */
	@ResourceKey(key="bean.roles.id")
	@Id
	@GeneratedValue(generator="role_gen_seq", strategy=GenerationType.SEQUENCE)
	@UnBound
	public Integer getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 * @return the role
	 */
	@UiComponentPosition(positionColumn="1", positionRow="1", tableDisplayColumn="1")
	@PropertyConstraints(isMandatory = MandatoryType.TURE, maxLength = "5", inputCaseType = StringInputCaseType.UPPERCASE, textInputDataType = TextFiledInputDataType.ONLYALPHA)
	@ResourceKey(key="bean.roles.role")
	@Column(name = "role", length = 5)
	public String getRole() {
		return role;
	}

	/**
	 * @param role the role to set
	 */
	public void setRole(String role) {
		this.role = role;
	}

	/**
	 * @return the description
	 */
	@ResourceKey(key="bean.roles.description")
	@UiComponentPosition(positionColumn="1", positionRow="2", tableDisplayColumn="2")
	@Column(name = "description", length = 100)
	public String getDescription() {
		return description;
	}

	/**
	 * @param description the description to set
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	/**
	 * @return the permissions
	 */
	@ResourceKey(key="bean.roles.permission")
	@UiComponentPosition(positionColumn="1", positionRow="3", tableDisplayColumn="-1")
	@ManyToMany(fetch=FetchType.LAZY, cascade=CascadeType.ALL)
	@JoinTable(name="eagle_perm_role", joinColumns={@JoinColumn(name = "userId", referencedColumnName="id")},
			inverseJoinColumns={@JoinColumn(name = "permissionId", referencedColumnName="id")})
	public List<PermissionsBean> getPermissions() {
		return permissions;
	}

	/**
	 * @param permissions the permissions to set
	 */
	public void setPermissions(List<PermissionsBean> permissions) {
		this.permissions = permissions;
	}

	/**
	 * @return the levelBeans
	 */
	@ResourceKey(key="bean.roles.level")
	@UiComponentPosition(positionColumn="1", positionRow="4", tableDisplayColumn="-1")
	@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, targetEntity=LevelsBean.class)
	public List<LevelsBean> getLevelBeans() {
		return levelBeans;
	}

	/**
	 * @param levelBeans the levelBeans to set
	 */
	public void setLevelBeans(List<LevelsBean> levelBeans) {
		this.levelBeans = levelBeans;
	}

	/**
	 * @return the isAllowed
	 */
	@Transient
	@ResourceKey(key="bean.roles.isAllow")
	@UiComponentPosition(positionColumn="1", positionRow="4", tableDisplayColumn="3")
	public Boolean getIsAllowed() {
		return isAllowed;
	}

	/**
	 * @param isAllowed the isAllowed to set
	 */
	public void setIsAllowed(Boolean isAllowed) {
		this.isAllowed = isAllowed;
	}

	/**
	 * @return the roleDate
	 */
	@Transient
	@ResourceKey(key="bean.roles.roleDate")
	@UiComponentPosition(positionColumn="1", positionRow="4", tableDisplayColumn="4")
	public Date getRoleDate() {
		return roleDate;
	}

	/**
	 * @param roleDate the roleDate to set
	 */
	public void setRoleDate(Date roleDate) {
		this.roleDate = roleDate;
	}
	
	
	/**
	 * @return the destinationType
	 */
	@Transient
	@ResourceKey(key="bean.roles.destinationType")
	@RadioButtons(values={
			@RadioButton(choice="s", label="Screen"), @RadioButton(choice = "pr", label="Printer"),
			@RadioButton(choice="f", label="File"), @RadioButton(choice="e", label="Email")})
	@UiComponentPosition(positionColumn = "1", positionRow = "10", tableDisplayColumn = "5")
	public String getDestinationType() {
		return destinationType;
	}

	/**
	 * @param destinationType the destinationType to set
	 */
	public void setDestinationType(String destinationType) {
		this.destinationType = destinationType;
	}

	/**
	 * @return the roleTitle
	 */
	@Transient
	@ResourceKey(key="bean.roles.title")
	@Enumerated(EnumType.STRING)
	@UiComponentPosition(positionColumn = "1", positionRow = "16", tableDisplayColumn="6")
	public UserTitlesEnum getRoleTitle() {
		return roleTitle;
	}

	/**
	 * @param roleTitle the roleTitle to set
	 */
	public void setRoleTitle(UserTitlesEnum roleTitle) {
		this.roleTitle = roleTitle;
	}
}
